
 <link rel="stylesheet" type="text/css" href="css/validationEngine.jquery.css">
<link rel="stylesheet" type="text/css" href="css/template.css">

<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/jquery.validationEngine-vi.js"></script>
<script type="text/javascript" src="js/jquery.validationEngine.js"></script>
<script>
        jQuery(document).ready(function(){
            // binds form submission and fields to the validation engine
            jQuery("#formID").validationEngine();
        });
</script>
<script>function Del_Info(str){
	var q=confirm('Bạn có chắc chắn muốn xóa hay không?');	
	if(q==true) 
		window.location=str;
	
}
</script>

<link rel="stylesheet" type="text/css" href="css/jquery-ui.css"/>
 
  <script type="text/javascript" src="js/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  var date = $('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' }).val();
  </script>
   <script>
  $(function() {
    $( "#datepicker1" ).datepicker();
  });
  var date = $('#datepicker1').datepicker({ dateFormat: 'dd-mm-yy' }).val();
  </script>
<?php
$sql="SELECT substr( QUYEN,1, 1 ) as mq
FROM qldl_tai_khoan
WHERE ten_dang_nhap = '".$_SESSION['username']."'";
	$query = @mysql_query($sql,$conn);
	$row = @mysql_fetch_array($query);
	if($row['mq']==1){
	 @header('Location: index.php?page=tour'); 
	}
	else {
	echo  "<script>alert ('Bạn không có quyền truy cập trang này!')</script>"; 
	echo "<meta http-equiv='refresh' content='0;url= index.php'>";
	}
?>
<!--<div class="cpanel-right-tttk">
  <div id="panel-sliders" class="pane-sliders">
    <div class="panel">-->
    <?php
			

			$sql1="select max(MA_TOUR) from qldl_tour "; 
			$result=mysql_query($sql1); 
			$kq=mysql_fetch_array($result); 
			$ma=$kq[0]+1; 
				?>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" style=" padding:10px;">
        <thead>
        <tr style=" padding-bottom:10px;">
        <th colspan="3" align="left" style="padding-bottom:10px;">QUẢN LÍ DANH MỤC TOUR</th>
        </tr> 
        </thead> 
        <tr valign="top" style="padding:5px;">
          <td width="40%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
            <form name="formID" id="formID" action="" method="post" enctype="multipart/form-data" >
            <table width="97%" height="477" border="1" bordercolor="#666666" class="adminlist_tt">
              <thead>
                <tr>
                  <th colspan="3"> Thông tin thêm tour</th>
                </tr>
              </thead>
            <tbody>
                
                <tr>
                  <td>Kiểu tour</td>
                  <td colspan="2">
                    
                    <select id="chon_kt" class="validate[required]" name="chon_kt">	
						<?php 
							$sql_ttp="select * from qldl_kieu_tour order by MA_KIEU asc";
							$query_ttp = @mysql_query($sql_ttp,$conn);
								
							echo "<option value='0' selected>Chọn kiểu tour</option>";
							while($row_ttp = mysql_fetch_array($query_ttp)){
						?>  
						<option value="<?php echo $row_ttp['MA_KIEU'];?>"><?php echo $row_ttp['TEN'];?></option>
							<?php }?> 
					</select>
                    </td>
                </tr>
                <tr>
                  <td>Tên tour</td>
                  <td colspan="2">
                    <label for="txt_ten_tour"></label>
                    <input type="text" class="validate[required] text-input" name="txt_ten_tour" id="txt_ten_tour" />
                  </td>
                  </tr>
                <tr>
                  <td>Giá</td>
                  <td colspan="2">
                    <label for="txt_gia"></label>
                    <input type="text" class="validate[required,custom[onlyNumberSp]]" name="txt_gia" id="txt_gia" />
                  </td>
                  </tr>
                <tr>
                  <td>Thời gian khởi hành</td>
                  <td colspan="2">
                    <label for="txt_tg_khoi_hanh"></label>
                   <input type="text" id="datepicker" name="txt_tg_bd">
                  </td>
                  </tr>
                <tr>
                  <td>Thời gian kết thúc</td>
                  <td colspan="2">
                    <label for="txt_tg_ket_thuc"></label>
                    <input type="text" id="datepicker1"  name="txt_tg_kt" align="left"/>
                  </td>
                  </tr>
                <tr>
                  <td>Số ngày</td>
                  <td colspan="2">
                    <label for="txt_so_ngay"></label>
                    <input type="text" class="validate[required,custom[onlyNumberSp]]" name="txt_so_ngay" id="txt_so_ngay" />
                  </td>
                  </tr>
                <tr>
                  <td>Số chỗ </td>
                  <td colspan="2">
                    <label for="txt_so_cho"></label>
                    <input type="text" class="validate[required,custom[onlyNumberSp]]" name="txt_so_cho" id="txt_so_cho" />
                  </td>
                  </tr>
           
                <tr>
                  <td>Diễn giải</td>
                  <td colspan="2">
                    <label for="area_dien_giai"></label>
                    <textarea name="area" id="area" cols="45" rows="5"></textarea>
                  </td>
                  </tr>
                <tr>
                  <td>Hình ảnh</td>
                  <td colspan="2">
                    <label for="txt_hinh_anh"></label>
                    <input type="file" name="file_up" />
                  </td>
                  </tr>
                <tr>
                  <td colspan="3" align="center"><strong>Thêm địa điểm du lịch</strong></td>
                </tr>
                <tr>
                  <td>Địa điểm 1</td>
                  <td colspan="2">
                    <select name="dd1" id="dd1" class="validate[required],trung[dd2],trung[dd3],trung[dd4],trung[dd5]"  >
                    <?php 
							$sql_dd="select * from qldl_dia_diem_du_lich order by MA_DIA_DIEM asc";
							$query_dd = @mysql_query($sql_dd,$conn);	
							echo "<option value='' selected>Chọn địa điểm 1</option>";
							if($query_dd)while($row_dd = @mysql_fetch_array($query_dd)){
						?>  
					<option value="<?php echo $row_dd['MA_DIA_DIEM'];?>"><?php echo $row_dd['DIA_DIEM'];?></option>
							<?php }?> 
                  </select></td>
                </tr>
                <tr>
                  <td>Địa điểm 2</td>
                  <td colspan="2">
                    <select name="dd2" id="dd2" class=" validate[trung[dd1],trung[dd3],trung[dd4],trung[dd5]]">
                    <?php 
							$sql_dd="select * from qldl_dia_diem_du_lich order by MA_DIA_DIEM asc";
							$query_dd = @mysql_query($sql_dd,$conn);	
								echo "<option value='' selected>Chọn địa điểm 2</option>";
							if($query_dd)while($row_dd = @mysql_fetch_array($query_dd)){
							
						?>  
						<option value="<?php echo $row_dd['MA_DIA_DIEM'];?>"><?php echo $row_dd['DIA_DIEM'];?></option>
							<?php 
								}
							
							?> 
                           
                  </select></td>
                </tr>
                <tr>
                  <td>Địa điểm 3</td>
                  <td colspan="2">
                    <select name="dd3" id="dd3" class="validate[trung[dd1],trung[dd2],trung[dd4],trung[dd5]]">
                    <?php 
							$sql_dd="select * from qldl_dia_diem_du_lich order by MA_DIA_DIEM asc";
							$query_dd = @mysql_query($sql_dd,$conn);	
								echo "<option value='' selected>Chọn địa điểm 3</option>";
							if($query_dd)while($row_dd = @mysql_fetch_array($query_dd)){
						?>  
						<option value="<?php echo $row_dd['MA_DIA_DIEM'];?>"><?php echo $row_dd['DIA_DIEM'];?></option>
							<?php }?> 
                  </select></td>
                </tr>
                <tr>
                  <td>Địa điểm 4</td>
                  <td colspan="2">
                  
                    <select name="dd4" id="dd4" class="validate[trung[dd1],trung[dd2],trung[dd3],trung[dd5]]">
                    <?php 
							$sql_dd="select * from qldl_dia_diem_du_lich order by MA_DIA_DIEM asc";
							$query_dd = @mysql_query($sql_dd,$conn);
								echo "<option value='' selected>Chọn địa điểm 4</option>";	
							if($query_dd)while($row_dd = @mysql_fetch_array($query_dd)){
						?>  
						<option value="<?php echo $row_dd['MA_DIA_DIEM'];?>"><?php echo $row_dd['DIA_DIEM'];?></option>
							<?php }?> 
                  </select></td>
                </tr>
                <tr>
                  <td>Địa điểm 5</td>
                  <td colspan="2">
                    <select name="dd5" id="dd5" class="validate[trung[dd1],trung[dd2],trung[dd3],trung[dd4]]">
                    <?php 
							$sql_dd="select * from qldl_dia_diem_du_lich order by MA_DIA_DIEM asc";
							$query_dd = @mysql_query($sql_dd,$conn);	
								echo "<option value='' selected>Chọn địa điểm 5</option>";
							if($query_dd)while($row_dd = @mysql_fetch_array($query_dd)){
						?>  
						<option value="<?php echo $row_dd['MA_DIA_DIEM'];?>"><?php echo $row_dd['DIA_DIEM'];?></option>
							<?php }?> 
                  </select></td>
                </tr>
                <tr>
                  <td colspan="3" align="center"><strong>Thêm phương tiện</strong></td>
                </tr>
                <tr>
                  <td>Phương tiện 1</td>
                  <td colspan="2"><select name="pt1" id="pt1" class="validate[required],trung[pt2],trung[pt3],trung[pt4]">
                    <?php 
							$sql_dd="select * from qldl_phuong_tien order by MA_PHUONG_TIEN asc";
							$query_dd = @mysql_query($sql_dd,$conn);
								echo "<option value='' selected>Chọn phương tiện 1</option>";	
							if($query_dd)while($row_dd = @mysql_fetch_array($query_dd)){
						?>  
						<option value="<?php echo $row_dd['MA_PHUONG_TIEN'];?>"><?php echo $row_dd['TEN_PHUONG_TIEN'];?></option>
							<?php }?> 
                  </select></td>
                </tr>
                <tr>
                  <td>Phương tiện 2</td>
                  <td colspan="2"><select name="pt2" id="pt2" class="validate[trung[pt1],trung[pt3],trung[pt4]]">
                    <?php 
							$sql_dd="select * from qldl_phuong_tien order by MA_PHUONG_TIEN asc";
							$query_dd = @mysql_query($sql_dd,$conn);	
							echo "<option value='' selected>Chọn phương tiện 2</option>";
							if($query_dd)while($row_dd = @mysql_fetch_array($query_dd)){
						?>  
						<option value="<?php echo $row_dd['MA_PHUONG_TIEN'];?>"><?php echo $row_dd['TEN_PHUONG_TIEN'];?></option>
							<?php }?> 
                  </select></td>
                </tr>
                <tr>
                  <td>Phương tiện 3</td>
                  <td colspan="2"><select name="pt3" id="pt3" class="validate[trung[pt1],trung[pt2],trung[pt4]]">
                    <?php 
							$sql_dd="select * from qldl_phuong_tien order by MA_PHUONG_TIEN asc";
							$query_dd = @mysql_query($sql_dd,$conn);
							echo "<option value='' selected>Chọn phương tiện 3</option>";	
							if($query_dd)while($row_dd = @mysql_fetch_array($query_dd)){
						?>  
						<option value="<?php echo $row_dd['MA_PHUONG_TIEN'];?>"><?php echo $row_dd['TEN_PHUONG_TIEN'];?></option>
							<?php }?> 
                  </select></td>
                </tr>
                 <tr>
                  <td>Phương tiện 4</td>
                  <td colspan="2"><select name="pt4" id="pt4" class="validate[trung[pt1],trung[pt3],trung[pt2]]">
                    <?php 
							$sql_dd="select * from qldl_phuong_tien order by MA_PHUONG_TIEN asc";
							$query_dd = @mysql_query($sql_dd,$conn);	
							echo "<option value='' selected>Chọn phương tiện 4</option>";
							if($query_dd)while($row_dd = @mysql_fetch_array($query_dd)){
						?>  
						<option value="<?php echo $row_dd['MA_PHUONG_TIEN'];?>"><?php echo $row_dd['TEN_PHUONG_TIEN'];?></option>
							<?php }?> 
                  </select></td>
                </tr>
                <tr>
                  <td colspan="3" align="left"><input type="submit" name="btn_add_tour" id="btn_add_tour" value="Lưu" /> 
                   <input type="submit" name="button" id="button" value="Hủy" />
                  <?php 
					if(isset($_POST['btn_add_tour'])){
				
					$kt = $_POST['chon_kt'];
					$tt = $_POST['txt_ten_tour'];
					$gia = $_POST['txt_gia'];
					$tgkh = $_POST['txt_tg_bd'];
					$tgkt = $_POST['txt_tg_kt'];
					$sn = $_POST['txt_so_ngay'];
					$sc = $_POST['txt_so_cho'];
					$dg = $_POST['area'];
					 
					$date = $tgkh;
					$arr_date = explode("/",$date);
					$day = $arr_date[1];
					$month = $arr_date[0];
					$year = $arr_date[2];
					$ngay = $year."-".$month."-".$day;	
					
					$date1 = $tgkt;
					$arr_date1 = explode("/",$date1);
					$day1 = $arr_date1[1];
					$month1 = $arr_date1[0];
					$year1 = $arr_date1[2];
					$ngay_kt = $year1."-".$month1."-".$day1;
					 if ($_FILES["file_up"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file_up"]["error"] . "<br />";
    }
  else
    {
    if (file_exists("tour/upload/news/" . $_FILES["file_up"]["name"]))
      {
      echo $_FILES["file_up"]["name"] . " da ton tai file tren server. ";
      }
    else
      {  
      move_uploaded_file($_FILES["file_up"]["tmp_name"],
      "tour/upload/news/" . $_FILES["file_up"]["name"]);	
	  $link = "tour/upload/news/" . $_FILES["file_up"]["name"];
	   
      }
	}
	$sql = "INSERT INTO qldl_tour VALUES('$ma','$kt','$tt','$gia','$ngay','$ngay_kt','$sn','$sc','$dg','$link')";
	$query = @mysql_query($sql,$conn);
	if(isset($_POST['btn_add_tour'])){
 					$d1 = $_POST['dd1'];
					$d2 = $_POST['dd2'];
					$d3 = $_POST['dd3'];
					$d4 = $_POST['dd4'];
					$d5 = $_POST['dd5'];
					$p1 = $_POST['pt1'];
					$p2 = $_POST['pt2'];
					$p3 = $_POST['pt3'];
					$p4 = $_POST['pt4'];
					if($_POST['dd1']<>""){
					$sql1 = "INSERT INTO qldl_chi_tiet_tour VALUES('$d1','$ma')";
					$query1 = @mysql_query($sql1,$conn);	
					}
					if($_POST['dd2']<>''){
					$sql2 = "INSERT INTO qldl_chi_tiet_tour VALUES('$d2','$ma')";
					
					$query2 = @mysql_query($sql2,$conn);		
					}
					if($_POST['dd3']<>''){
					$sql3 = "INSERT INTO qldl_chi_tiet_tour VALUES('$d3','$ma')";
					
					$query3 = @mysql_query($sql3,$conn);		
					}
					if($_POST['dd4']<>''){
					$sql4 = "INSERT INTO qldl_chi_tiet_tour VALUES('$d4','$ma')";
					
					$query4 = @mysql_query($sql4,$conn);		
					}
					if($_POST['dd5']<>''){
					$sql5 = "INSERT INTO qldl_chi_tiet_tour VALUES('$d5','$ma')";
				
					$query5 = @mysql_query($sql5,$conn);		
					}
					if($_POST['pt1']<>''){
					$sql6 = "INSERT INTO qldl_chi_tiet_phuong_tien VALUES('$p1','$ma')";
					$query6 = @mysql_query($sql6,$conn);
					}
					if($_POST['pt2']<>''){
					$sql7 = "INSERT INTO qldl_chi_tiet_phuong_tien VALUES('$p2','$ma')";
					$query7 = @mysql_query($sql7,$conn);	
					}
					if($_POST['pt3']<>''){
					$sql8 = "INSERT INTO qldl_chi_tiet_phuong_tien VALUES('$p3','$ma')";
					$query8 = @mysql_query($sql8,$conn);
					}
					if($_POST['pt4']<>''){
					$sql9 = "INSERT INTO qldl_chi_tiet_phuong_tien VALUES('$p4','$ma')";
					$query9 = @mysql_query($sq9,$conn);
					}
	}
					

						if($query)echo "<script>alert ('Thêm thông tin thành công.')</script>";	
						else echo "<script>alert ('Thêm không thành công!')</script>";
						
					}
					?>
                  </td>
                  </tr>
                <tr>
                  <td colspan="3" align="left"><input type="submit" name="btn_them_quoc_gia" id="btn_them_quoc_gia" value="Thêm quốc gia" onclick='window.location.href="index.php?page=qg"' /> 
                   <input type="submit" name="btn_them_thanh_pho" id="btn_them_thanh_pho" value="Thêm thành phố" onclick='window.location.href="index.php?page=ttp"' /></td>
                  </tr>
                
              </tbody>
            </table>
            </form>
          </div></td>
          <td width="70%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
            <table width="100%" border="1" bordercolor="#666666" class="adminlist_tt">
              <thead>
                <tr>
                  <th colspan="7" align="center"> Danh sách tour </th>
                  <?php include('tour/del.php'); ?>
                </tr>
              </thead>
              <tbody>
                <form action="" method="post" name="form_view" id="form_view">
                <tr>
                  <td width="55">Mã tour</td>
                  <td width="147">Tên tour</td>
                  <td width="89" align="center">Giá</td>
                  <td width="121">Thời gian khởi hành</td>
                  <td width="58" align="center">Số ngày</td>
                  <td width="70">Số chỗ </td>
                  <td width="115">Cập nhật</td>
                  </tr>
                  <?php
				$stt=0;
	$sql="select * from qldl_tour order by MA_TOUR asc ";
	$query = @mysql_query($sql,$conn);	
	if(!$query) echo "Query error to display.";
	else while($row = @mysql_fetch_array($query)){
		$stt++;
			?>
            	
                <tr>
                  <td><?php echo $row['MA_TOUR'];;?></td>
                  <td><?php echo $row['TEN_TOUR'];?></td>
                  <td><?php echo $row['GIA'];?></td>
                  <td> <?php
				  $date = $row['TG_KHOI_HANH'];
					$arr_date = explode("-",$date);
					$day = $arr_date[2];
					$month = $arr_date[1];
					$year = $arr_date[0];
					$ngay_kh = $day."/".$month."/".$year;	
				  echo $ngay_kh;?></td>
                  <td><?php echo $row['SO_NGAY'];?></td>
                  <td><?php echo $row['SO_CHO'];?></td>
                  <td><a href="index.php?page=id_edit_tour&amp;id_edit_tour=<?php echo $row['MA_TOUR'];?>&amp;id_kt=<?php echo $row['MA_KIEU'];?>">Sửa</a> || 
                  <a onclick="Del_Info('index.php?page=tour&amp;id_del_tour=<?php echo $row['MA_TOUR'];?>&amp;id_photo_tour=<?php echo $row['HINH_ANH']; ?>');" href="#">Xóa</a></td>
                  </tr>
                  <?php } ?>
                  </form>
              </tbody>
            </table>
          </div></td>
        </tr>
      </table>
   <!-- </div>
  </div>
</div>-->